#pragma once
#include "pch.h"
#include "Common.h"
#include <dl_creationadapter.h>

class DL_VertexData;
class DL_PolylineData;

class CDXFReader :public DL_CreationAdapter {
public:
	bool loadDXF(const std::string& vFilePath, std::vector<std::vector<Point2D>>& voPolylineSet);
	const auto getAABB()const { return m_AABB_Box; }
	bool isEmpty() { return m_PolylineSet.empty(); }


#ifdef _UNIT_TEST
	void calAABB() { __calAABB(); };
	void removeBBoxCornerPoints() { __removeBBoxCornerPoints(); };
	void mapBBoxBeginFromOrigin() { __mapBBoxBeginFromOrigin(); };
	void addLastPolyline()
	{
		if (!m_Polyline.empty())
		{
			m_PolylineSet.emplace_front(m_Polyline);
			m_Polyline.clear();
		}
	};
	std::pair<Point2D, Point2D> getAABBB() { return m_AABB_Box; };
	std::vector<std::vector<Point2D>> getSet()
	{
		std::vector<std::vector<Point2D>> PolylineSet;
		for (auto Polyline : m_PolylineSet)
		{
			std::vector<Point2D> TempPolyline;
			for (auto Iter = Polyline.cbegin(); Iter != Polyline.cend(); Iter++)
				TempPolyline.emplace_back(*(Iter));
			PolylineSet.emplace_back(TempPolyline);
		}
		return PolylineSet;
	};
#endif

private:
	virtual void addVertex(const DL_VertexData& vVertex) override;
	virtual void addPolyline(const DL_PolylineData& vPolyline) override;
	void __addLastPolyline();
	void __calAABB();
	void __removeBBoxCornerPoints();
	void __clear() { m_PolylineSet.clear(); m_Polyline.clear(); }
	void __getPolylineSet(std::vector<std::vector<Point2D>>& voPolylineSet);

	std::forward_list<std::forward_list<Point2D>> m_PolylineSet;
	std::forward_list<Point2D> m_Polyline;
	std::pair<Point2D, Point2D> m_AABB_Box;
};
